<?php

namespace app\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\EShop;

/**
 * EShopQuery represents the model behind the search form about `\app\models\EShop`.
 */
class EShopQuery extends EShop
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'mini_programs_id', 'name', 'logo_url', 'brief_introduction', 'cert_url', 'key_url', 'root_url', 'create_datetime'], 'safe'],
            [['is_on', 'is_main'], 'integer'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = EShop::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'is_on' => $this->is_on,
            'is_main' => $this->is_main,
            'create_datetime' => $this->create_datetime,
        ]);

        $query->andFilterWhere(['like', 'id', $this->id])
            ->andFilterWhere(['like', 'mini_programs_id', $this->mini_programs_id])
            ->andFilterWhere(['like', 'name', $this->name])
            ->andFilterWhere(['like', 'logo_url', $this->logo_url])
            ->andFilterWhere(['like', 'brief_introduction', $this->brief_introduction])
            ->andFilterWhere(['like', 'cert_url', $this->cert_url])
            ->andFilterWhere(['like', 'key_url', $this->key_url])
            ->andFilterWhere(['like', 'root_url', $this->root_url]);

        return $dataProvider;
    }
}
